package com.leoman.plz_p.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.leoman.plz_p.R;
import com.leoman.plz_p.module.bean.BookListBean;

import cn.com.corelib.utils.adapter.BaseAdapterHelper;
import cn.com.corelib.utils.adapter.normal.QuickAdapter;

/**
 * Created by guoh on 2018/7/8.
 */
public class
SectionAdapter extends QuickAdapter<BookListBean> {

    private ClassAdapter adapter;


    public SectionAdapter(Context context) {
        super(context, R.layout.item_section);
    }

    @Override
    protected void convert(final BaseAdapterHelper helper, BookListBean item, final int position) {
        helper.setText(R.id.tv_title_name,item.getName());
        helper.setText(R.id.tv_title_level,TextUtils.isEmpty(item.getLevelName())?"":"级别 "+item.getLevelName());
        adapter=new ClassAdapter(context);
        adapter.replaceAll(item.getList());
        helper.setAdapter(R.id.ls_class,adapter);

        switch (item.getStatus()){
            case 1:
                helper.setBackgroundRes(R.id.iv_title_progress,R.mipmap.icon_zero_to_four);
                break;
            case 2:
                helper.setBackgroundRes(R.id.iv_title_progress,R.mipmap.icon_one_to_one);
                break;
        }

        helper.getView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                helper.setVisible(R.id.ls_class,helper.getView(R.id.ls_class).getVisibility()==View.VISIBLE?false:true);
                if (helper.getView(R.id.ls_class).getVisibility()==View.VISIBLE){
                    helper.setBackgroundRes(R.id.iv_title_open,R.mipmap.icon_up_gary);
                }else {
                    helper.setBackgroundRes(R.id.iv_title_open,R.mipmap.icon_down_gary);
                }
            }
        });

        helper.getView(R.id.iv_title_open).setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               helper.setVisible(R.id.ls_class,helper.getView(R.id.ls_class).getVisibility()==View.VISIBLE?false:true);
               if (helper.getView(R.id.ls_class).getVisibility()==View.VISIBLE){
                   helper.setBackgroundRes(R.id.iv_title_open,R.mipmap.icon_up_gary);
               }else {
                   helper.setBackgroundRes(R.id.iv_title_open,R.mipmap.icon_down_gary);
               }
            }
       });
        adapter.setOnItemClick(new ClassAdapter.onItemClick() {
            @Override
            public void onSafeClick(int p) {
                if (onItemClick!=null){
                    onItemClick.onSafeClick(position,p);
                }
            }

            @Override
            public void onRequestClick(int p) {
                if (onItemClick!=null){
                    onItemClick.onRequestClick(position,p);
                }
            }

            @Override
            public void onVideoClick(int parent, int child) {
                if (onItemClick!=null){
                    onItemClick.onVideoClick(position,parent,child);
                }
            }

            @Override
            public void onExamClick(int parent, int child) {
                if (onItemClick!=null){
                    onItemClick.onExamClick(position,parent,child);
                }
            }

            @Override
            public void onTestClick(int parent, int child) {
                if (onItemClick!=null){
                    onItemClick.onTestClick(position,parent,child);
                }
            }
        });

    }

    public void setOnItemClick(onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    private onItemClick onItemClick;

    public interface onItemClick{
        void onSafeClick(int parent, int position);
        void onRequestClick(int parent, int position);
        void onVideoClick(int parent1, int parent2, int child);
        void onExamClick(int parent1, int parent2, int child);
        void onTestClick(int parent1, int parent2, int child);
    }


}
